/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.infodb.config.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.hyts.infodb.config.bean.ConfigDataBO;
import com.hyts.infodb.config.bean.ConfigDataPO;
import com.hyts.infodb.config.bean.ConfigDataVO;
import com.hyts.infodb.config.dao.ConfigDataDAO;
import com.hyts.infodb.config.service.ConfigDataService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @project-name:infodb
 * @package-name:com.hyts.infodb.config.service.impl
 * @author:LiBo/Alex
 * @create-date:2020-02-20 22:37
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
@Service
public class ConfigDataServiceImpl implements ConfigDataService {


    @Autowired
    ConfigDataDAO configDataDAO;

    /**
     * 查询数据信息
     * @param param
     * @return
     */
    @Override
    public List<ConfigDataVO> findData(ConfigDataBO param) {
        ConfigDataPO configDataPO = new ConfigDataPO();
        BeanUtils.copyProperties(param,configDataPO);
        List<ConfigDataPO> configDataPOS = configDataDAO.findAll(Example.of(configDataPO));
        if(CollectionUtils.isNotEmpty(configDataPOS)){
            return configDataPOS.parallelStream().map(element->{
                ConfigDataVO configDataVO = new ConfigDataVO();
                BeanUtils.copyProperties(element,configDataVO);
                return configDataVO;
            }).collect(Collectors.toList());
        }
        return Lists.newArrayList();
    }

    @Override
    public ConfigDataVO pageData(ConfigDataBO param) {
        return null;
    }

    @Override
    public ConfigDataVO loadData(ConfigDataBO param) {
        return null;
    }

    @Override
    public ConfigDataVO deleteData(ConfigDataBO param) {
        return null;
    }

    @Override
    public ConfigDataVO saveData(ConfigDataBO param) {
        return null;
    }

    @Override
    public JSONObject getConfigDataTypeList(String code) {
        return null;
    }
}
